package lab2Exercise2;

import java.util.ArrayList;

public class ArrayListQueue<E> implements Queue<E> {
	private int f; // front of queue
	private int r; // rear of queue
	private ArrayList<E> Q;
	
	public ArrayListQueue()
	{
		Q = new ArrayList<E>();
		f = 0;
		r = 0;
	}
	
	public int size()
	{
		return Q.size();
	}
	
	public boolean isEmpty()
	{
		return Q.isEmpty();
	}
	
	public E front() throws QueueException
	{
		if(isEmpty()) {
			throw new QueueException("Queue is empty");
		}
		return Q.get(0);
	}
	
	public E dequeue() throws QueueException
	{
		if(isEmpty()) {
			throw new QueueException("Queue is empty");
		}
		E tmp = Q.get(0);
		Q.remove(0);
		return tmp;
	}
	public void enqueue(E e)
	{
		Q.add(e);
		r = r + 1;
	}
	
	public String toString()
	{
    	StringBuffer buff = new StringBuffer("[");
    	
    	for(int i = 0; i < Q.size(); i++) {
    		if((i+1) == Q.size()) {
    			buff.append(Q.get(i));
    		} else {
    			buff.append(Q.get(i) + ",");
    		}
    		 
    	}
    	buff.append("]");
    	return buff.toString();
	}
     

}
